package cn.ghx.xboot.props;

import cn.ghx.xboot.common.Result;
import cn.ghx.xboot.setting.Setting;
import cn.ghx.xboot.setting.SettingService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/props")
public class PropsController {

    public static final String POST = "";
    public static final String GET_LIST = "/list";
    public static final String DELETE = "/{id}";

    private final PropsService service;

    public PropsController(PropsService service) {
        this.service = service;
    }

    @DeleteMapping(DELETE)
    public Result<Boolean> delete(@PathVariable String id){
        return Result.success(service.removeById(id));
    }

    @PostMapping(POST)
    public Result<Boolean> save(@RequestBody Props item){
        return Result.success(service.saveOrUpdate(item));
    }

    @GetMapping(GET_LIST)
    public Result<Page<Props>> getList(
            @RequestParam(required = false) String keyword ,
            @RequestParam(required = false,defaultValue = "1") Integer page ,
            @RequestParam(required = false,defaultValue = "10") Integer size){
        return Result.success(service.query(keyword,page,size));
    }
}
